package com.wolf.config;

import com.wolf.client.WolfClientBeanProcessor;
import com.wolf.serialization.SerialFactory;
import com.wolf.server.WolfServerInitializerProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * @auth: dylan
 * @Desc: 自动装配类
 * @Time: 2024/4/29
 */
@ComponentScan("com.wolf")
@EnableConfigurationProperties({ServerProperties.class, ClientProperties.class})
public class WolfAutoConfiguration {
    @ConditionalOnProperty(
            prefix = "wolf.server.",
            name = {"port"}
    )
    @Bean
    public WolfServerInitializerProcessor wolfServerInitializerProcessor(ServerProperties serverProperties) {
        return new WolfServerInitializerProcessor(serverProperties);
    }

    @ConditionalOnProperty(
            prefix = "wolf.client.",
            name = {"host","port"}
    )
    @Bean
    public WolfClientBeanProcessor wolfClientBeanProcessor(ClientProperties clientProperties){
        clientProperties.setPort(2181);
        clientProperties.setHost("127.0.0.1");
        return new WolfClientBeanProcessor(clientProperties);
    }

    /**
     * 初始化序列化器
     */
    @Bean
    @ConditionalOnMissingBean(SerialFactory.class)
    public SerialFactory serialFactory() {
        return new SerialFactory();
    }



}
